package main

import (
	"fmt"
	"sort"
)

func deleteGreatestValue(grid [][]int) int {
	for _, row := range grid {
		sort.Slice(row, func(i, j int) bool {
			return row[i] < row[j]
		})
	}
	//fmt.Println(grid)
	res := 0
	for i := 0; i < len(grid[0]); i++ {
		//fmt.Println(maxOfCol(grid, i))
		res += maxOfCol(grid, i)
	}

	return res
}
func maxOfCol(grid [][]int, col int) int {
	max := grid[0][col]
	for i := 0; i < len(grid); i++ {
		if grid[i][col] > max {
			max = grid[i][col]
		}
	}
	return max
}

func main() {
	grid := [][]int{{1, 2, 4}, {3, 3, 1}}
	res := deleteGreatestValue(grid)
	fmt.Println(res)
}
